package cn.edu.ujn.food.service;

import cn.edu.ujn.food.entity.Ingredientstock;
import cn.edu.ujn.food.dao.IngredientstockDao;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

@Service("ingredientstockService")
public class IngredientstockServiceImpl implements IngredientstockService {
    @Resource
    private IngredientstockDao ingredientstockDao;

    @Override
    public Ingredientstock queryById( Integer ingreId) {
        return this.ingredientstockDao.queryById(ingreId);
    }

    @Override
    public Page<Ingredientstock> queryByPage(Ingredientstock ingredientstock, PageRequest pageRequest) {
        long total = this.ingredientstockDao.count(ingredientstock);
        return new PageImpl<>(this.ingredientstockDao.queryAllByLimit(ingredientstock, pageRequest), pageRequest, total);
    }

    @Override
    public Ingredientstock insert(Ingredientstock ingredientstock) {
        this.ingredientstockDao.insert(ingredientstock);
        return ingredientstock;
    }

    @Override
    public boolean deleteById(Integer ingreId) {
        return this.ingredientstockDao.deleteById(ingreId) > 0;
    }

    @Override
    public cn.edu.ujn.util.Page<Ingredientstock> selectAll(Ingredientstock ingredientstock) {
        List<Ingredientstock> ingredientstocks = ingredientstockDao.selectAll(ingredientstock);
        cn.edu.ujn.util.Page<Ingredientstock> page = new cn.edu.ujn.util.Page<>();
        page.setPage(ingredientstock.getStart());
        page.setRows(ingredientstocks);
        page.setSize(ingredientstock.getRows());
        page.setTotal(ingredientstockDao.selectCount());
        return page;
    }

    @Override
    public Ingredientstock update(Ingredientstock ingredientstock) {
        this.ingredientstockDao.update(ingredientstock);
        return null;
    }
}
